package com.our.shop.system.util;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;


public abstract class AbstractPageList implements PageList {
	
	protected int totalSize;
	
	protected int pageSize;

	protected int currentPage;

	protected List<Object> pageList;
	
	/*--------------- implements PagingList ------------------*/

	public int getTotalPage() {
		int mod = totalSize % pageSize;
		if (mod > 0) {
			return (totalSize + pageSize - mod) / pageSize;
		}
		return totalSize / pageSize;
	}
	
	public int getCurrentPage() {
		return currentPage;
	}
	
	public boolean isFirstPage() {
		return currentPage <= 1;
	}

	public boolean isMiddlePage() {
		return ! isFirstPage() && ! isLastPage();
	}

	public boolean isLastPage() {
		return currentPage >= getTotalPage();
	}
	
	public int getBeginIndex() {
		return pageSize * (currentPage - 1);
	}

	public int getEndIndex() {
		return getBeginIndex() + size();
	}
	
	public int getTotalSize() {
		return totalSize;
	}

	public int getMaxSize() {
		return pageSize;
	}

	public int getSize() {
		return size();
	}

	public List<Object> getList() {
		return pageList;
	}

	/*--------------- adapter implements List ------------------*/
	
	public int size() {
		return pageList.size();
	}

	public boolean isEmpty() {
		return pageList.isEmpty();
	}

	public boolean contains(Object o) {
		return pageList.contains(o);
	}

	public Iterator<Object> iterator() {
		return pageList.iterator();
	}

	public Object[] toArray() {
		return pageList.toArray();
	}

	public Object[] toArray(Object a[]) {
		return pageList.toArray(a);
	}

	public boolean containsAll(Collection<?> c) {
		return pageList.containsAll(c);
	}

	public Object get(int index) {
		return pageList.get(index);
	}

	public int indexOf(Object o) {
		return pageList.indexOf(o);
	}

	public int lastIndexOf(Object o) {
		return pageList.lastIndexOf(o);
	}

	public ListIterator<Object> listIterator() {
		return pageList.listIterator();
	}

	public ListIterator<Object> listIterator(int index) {
		return pageList.listIterator(index);
	}

	public List<Object> subList(int fromIndex, int toIndex) {
		return pageList.subList(fromIndex, toIndex);
	}

	public boolean add(Object o) {
		return pageList.add(o);
	}

	public boolean remove(Object o) {
		return pageList.remove(o);
	}

	public boolean addAll(Collection<?> c) {
		return pageList.addAll(c);
	}

	public boolean addAll(int index, Collection<?> c) {
		return pageList.addAll(index, c);
	}

	public boolean removeAll(Collection<?> c) {
		return pageList.removeAll(c);
	}

	public boolean retainAll(Collection<?> c) {
		return pageList.retainAll(c);
	}

	public void clear() {
		pageList.clear();
	}

	public Object set(int index, Object element) {
		return pageList.set(index, element);
	}

	public void add(int index, Object element) {
		pageList.add(index, element);
	}

	public Object remove(int index) {
		return pageList.remove(index);
	}

}
